Skip to content

Stop pipelined generation when consumer drops the stream#113

Merged
stikves merged 1 commit into
apple:mainfrom
stikves:fix/pipelined-early-stop
Jul 17, 2026
Merged

Stop pipelined generation when consumer drops the stream#113
stikves merged 1 commit into
apple:mainfrom
stikves:fix/pipelined-early-stop

Conversation

@stikves

@stikves stikves commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

When the consumer breaks out of the token stream (e.g. at EOS), the forwarding loop now detects the terminated yield result and finishes the inner token continuation, which signals the GPU producer to stop.

Additionally, outputContinuation.onTermination finishes the inner stream so cancellation propagates even if the forwarding loop hasn't started iterating yet.

Also cancel any prior active generation at the start of generate() on all engine types (sequential, static-shape, VLM). This ensures the cancel-and-replace contract is upheld regardless of which engine is in use, preventing state overlap between turns.

When the consumer breaks out of the token stream (e.g. at EOS), the
forwarding loop now detects the terminated yield result and finishes
the inner token continuation, which signals the GPU producer to stop.

Additionally, outputContinuation.onTermination finishes the inner
stream so cancellation propagates even if the forwarding loop hasn't
started iterating yet.

Also cancel any prior active generation at the start of generate() on
all engine types (sequential, static-shape, VLM). This ensures the
cancel-and-replace contract is upheld regardless of which engine is
in use, preventing state overlap between turns.
@stikves stikves self-assigned this Jul 17, 2026
@stikves
stikves marked this pull request as ready for review July 17, 2026 16:56
@stikves
stikves merged commit 04a3fd6 into apple:main Jul 17, 2026
3 checks passed
@stikves
stikves deleted the fix/pipelined-early-stop branch July 17, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants